# 列表
"""
import os
a = ['aa', 'ss', 'dd', 'ff']
print(a[1: 3])
print(type(a))
c = "hahah "
print(c.isalpha())
os.system("cls")

a = [1,2,3]
b = ["ss", "yui", "kxkx"]
# 合并俩个数组 不同类型都可以
# a = a + b
a.append(b) # 这样是吧b作为一个数据储存在a中
print(a[3][1]) # 和c有相同的访问方法-

# # 模拟购物
container = [] # 储存商品

flag = True
while flag:
    price = 0
    count = 0
    name = input("亲输入你要储存的商品名字")
    while flag:# 数字才能储存
        price = input("亲输入商品价格")
        if price.isdigit():
            flag = False
    flag = True
    while flag:
        count = input("有多少件呀")
        if count.isdigit():
            flag = False
    flag = True
    goods = [name, price, count]
    container.append(goods)
    flag1 = input("还要储存吗Y/y")
    if flag1.lower() != 'y':
        flag = False
# 打印储存的商品
# 商品数
count = 0
cost = 0
for goods in container: # 用for in遍历
    print(goods)
    count += int(goods[2])
    cost += (int(goods[1])*int(goods[2]))
print("总价格为%d \n总数量为%d" % (cost, count))
# 元素的删除 pop clear remove
s = ["书包", "书包", "外套","书包", "电脑包", "书包", "笔记本", "裤子", "书", "何止", "插座"]
# print(s[3])
# s.pop(3)# 删除指定的下标的元素 参数是数字 若无参数默认未删
# print(s)
# s.clear()# 清空列表
# print(s)
# s.remove("书包")# 删除指定的元素名陈 没有就抱错
# print(s)
# 判断列表中是否又该袁术
# if "书包" in s:
#     print("yes")
# else:
#     print("no")
# 删除指定所有元素
ss = ["书包", "书包", "外套", "书包", "电脑包", "书包", "笔记本", "裤子", "书", "何止", "插座"]
flag = True
delt = input("输入你想删除的数")
# while flag:
#     if delt in ss:
#         ss.remove(delt)
#     else:
#         flag = False
# print(ss)
i = 0
# while i < len(ss)-1:
#     if ss[i] == delt:
#         ss.pop(i)
#     else:
#         i += 1
# print(ss)
# while i < len(ss)-1:
#     if ss[i] == delt:
#         ss.remove(delt)
#     else:
#         i += 1
# print(ss)
while flag:
    for i in ss:
        if i == delt:
            ss.remove(delt)
        flag = False
    if delt in ss:
        flag = True
print(ss)
print(len(ss))
# 修改 查找 插入insert
s = [1, 2, 3, 43, 5, 6, 7]
id1 = s.index(3) # 放回该位置的下标 没有报错
print(id1, s[id1])
s.insert(3,"hj")# 参数，(下表，元素)在指定的下表下插入自定的元素
print(s)
# 删除 del pop(删除指定元素） clear(清除整个列表)
s = [1, 0, 2, 3, 4, 5]
s2 = s
# del s2 # s s2都是指向[1, 0, 2, 3, 4, 5]这块空寂，而删除的s2也就是删除
# s2与这块空间的联系，并且删除了s2这个变量，而这块空间为删除
# print(s2)# 会包未定义的错误
print(s)
del s2[3]
print(s2)
import random

# 排序 sort reverse
numbers = []
for i in range(10):
    ran = random.randint(1, 1000)
    numbers.append(ran)
# numbers.sort()# 默认升序
# numbers.sort(reverse=True)# reverse=False是升序 reverse=True是降序
print(numbers)
numbers.reverse()# 将列表单纯倒置
print(numbers)
import random

number = []
for i in range(8):
    ran = random.randint(1, 100)
    number.append(ran)
number.sort()
print(number)
number.append(int(input("输入一个数字")))
number.sort()
print(number)
"""
# 冒泡排序
import random

num = []
for i in range(7):
    ran = random.randint(1, 100)
    num.append(ran)
print(num)
for j in range(len(num)-1): # 升序
    for k in range(len(num)-1-j):
        if num[k] > num[k+1]:
            num[k], num[k+1] = num[k+1], num[k]
print(num)